///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef __BUOLA_PYTHON_TYPES_YMATRIX_H__
#define __BUOLA_PYTHON_TYPES_YMATRIX_H__

#include <buola/python/types/yobject.h>

namespace buola { namespace python {

class YMatrix : public YObject
{
public:
    YMatrix(PyObject *pPyObject,bool /*pIncRef*/=true)
            : YObject(pPyObject)
    {
    }

    explicit YMatrix(const YObject &pPython)
            : YObject(pPython)
    {
    }

    YMatrix(int pRowCount,int pColCount,const YObject &pPopulate=YObject())
            : YObject(PyList_New(pRowCount),false)
    {
        for(int i=0;i<pRowCount;i++)
        {
            YList lList(pColCount,pPopulate);
            lList.IncRef();
            PyList_SET_ITEM(mPyObject,i,lList);
        }
    }

    int GetRowCount()
    {
        return PyList_Size(mPyObject);
    }

    int GetColCount()
    {
        if(PyList_Size(mPyObject)==0) return 0;
        return PyList_Size(PyList_GET_ITEM(mPyObject,0));
    }

    PyObject *Get(int r,int c)
    {
        YList lRow(PyList_GET_ITEM(mPyObject,r));
        return lRow[c];
    }

    void Set(int r,int c,const YObject &pValue)
    {
        YList lRow(PyList_GET_ITEM(mPyObject,r));
        lRow.Set(c,pValue);
    }
};

/*namespace python*/ } /*namespace buola*/ }

#endif
